
#ifndef STYLEEDIT_H
#define STYLEEDIT_H

#include <BMap>
#include <BFont>
#include <BImage>
#include <BTextEdit>

using namespace BWE;

class StyleFormat : public BTextFormat
{
public:
	StyleFormat();
	~StyleFormat();

	virtual const BFont* font(int pos) const
	{
		auto cit = _nodeMap <= pos;
		if (cit.valid() && pos < cit->end)
			return cit->font;
		return 0;
	}
	virtual const BColor* color(int pos) const
	{
		auto cit = _nodeMap <= pos;
		if (cit.valid() && pos < cit->end)
			return &cit->color;
		return 0;
	}

protected:
	struct Node
	{
		const BFont*	font;
		BColor			color;
		int				end;
	};

	Node& insert(int pos, int end)
	{
		auto it = _nodeMap.insert(pos);
		it->end = end;
		return *it;
	}

	virtual void styled(const BStyle* style) override;
	virtual void changed(const BString& text) override;

protected:
	void slotAssetChanged(BObject* object, const BValue& value);

	void slotEditStyled(BObject* object, const BValue& value);
	void slotEditFreshed(BObject* object, const BValue& value);
	void slotEditFramed(BObject* object, const BValue& value);

private:
	BTextEdit*			_textEdit;
	BString				_fileName;
	const BFont*		_nameFont;
	const BFont*		_signFont;
	const BFont*		_noteFont;
	bool				_dirtyLines;
	BMap<int, Node>		_nodeMap;

};

#endif